<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/7/23
 * Time: 15:25
 */

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\activity\LimitTimeRobbing as mLimitTimeRobbing;
use Biz\model\activity\FlashSale as mFlashSale;

$sql = 'SELECT distinct start_time,end_time from limit_time_robbing';

$data = mLimitTimeRobbing::query($sql)->fetchAll();

$i = 0;
foreach ($data as $value)
{
    $list[$i]['start_time'] = $value['start_time'];
    $list[$i]['end_time'] = $value['end_time'];
    $list[$i]['addtime'] = date('Y-m-d H:i:s');
    $list[$i]['edittime'] = date('Y-m-d H:i:s');

    $i++;
}
$result = mFlashSale::insert($list)->rowcount();

if ($result) {
    var_dump('数据同步成功');
}

$data = mFlashSale::select(['id', 'start_time', 'end_time'], ['status' => 1]);

foreach($data as $value)
{
    $result = mLimitTimeRobbing::update(['flash_sale_id' => $value['id']], [
        'start_time' => $value['start_time'],
        'end_time' => $value['end_time'],
    ]);

    if ($result) {
        var_dump($value['id'].'修复成功');
    }
}
